﻿using System;
using System.Windows.Navigation;

namespace TakePhotoTogether
{
    class CustomUriMapper : UriMapperBase
    {

        public override Uri MapUri(Uri uri)
        {
            string tempUri = uri.ToString();
            string mappedUri;


            // Launch from the photo apps picker.
            // This is for only Windows Phone OS 7.1 apps.
            // Incoming URI example: /MainPage.xaml?token=%7B273fea8d-134c-4764-870d-42224d13eb1a%7D
            if ((tempUri.Contains("token")) && !(tempUri.Contains("RichMediaEdit")))
            {
                // Redirect to PhotoPage.xaml.
                mappedUri = tempUri.Replace("MainPage", "PhotoPage");
                return new Uri(mappedUri, UriKind.Relative);
            }

            // Launch from the rich media "Open in" link.
            // This is only for Windows Phone 8 apps.
            // Incoming URI example: /MainPage.xaml?Action=RichMediaEdit&token=%7Bed8b7de8-6cf9-454e-afe4-abb60ef75160%7D
            if ((tempUri.Contains("RichMediaEdit")) && (tempUri.Contains("token")))
            {
                // Redirect to RichMediaPage.xaml.
                mappedUri = tempUri.Replace("MainPage", "MainPage");
                return new Uri(mappedUri, UriKind.Relative);
            }


            // Otherwise perform normal launch.
            return uri;
        }
    }
}
